package anveshitha.analyzers;

import static anveshitha.config.AnveshithaConstants.ENGLISH_STOP_WORDS;
import static anveshitha.config.AnveshithaConstants.JAVA_STOP_WORDS;

import java.io.Reader;
import java.util.Set;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.LowerCaseTokenizer;
import org.apache.lucene.analysis.PorterStemFilter;
import org.apache.lucene.analysis.StopFilter;
import org.apache.lucene.analysis.TokenStream;

import anveshitha.config.AnveshithaConstants.FieldEnum;


public class JavaSourceCodeAnalyzer extends Analyzer {

	private Set javaStopSet; 
	private Set englishStopSet; 
	
	public JavaSourceCodeAnalyzer(){
		super();
		javaStopSet = StopFilter.makeStopSet(JAVA_STOP_WORDS);
		englishStopSet = StopFilter.makeStopSet(ENGLISH_STOP_WORDS);
	}
	
	public TokenStream tokenStream(String fieldName, Reader reader) {
		if (fieldName.equals(FieldEnum.COMMENTS.name()))
			return   new PorterStemFilter(new StopFilter(new LowerCaseTokenizer(reader), englishStopSet));
		else
			return   new StopFilter( new LowerCaseTokenizer(reader),javaStopSet);
	  }
}
